package com.example.supermarket.mapper;

import com.example.supermarket.entity.Order;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>订单表映射器<p/>
 *
 * @Author: porridge
 * @Date:2021/10/8 19:52
 */
@Mapper
@Repository
public interface OrderMapper {

    /**
     * <p>对订单的插入<p/>
     * @param goodsId
     * @param memberId
     * @param payStatus
     * @param orderId
     * @param createTime
     * @return
     */
    @Insert("insert into `order`(goods_id, member_id, pay_status, order_id, create_time) values(#{goodsId}, #{memberId}, #{payStatus}, #{orderId}, #{createTime})")
    int insert(@Param("goodsId")int goodsId, @Param("memberId")int memberId, @Param("payStatus")int payStatus, @Param("orderId")String orderId, @Param("createTime")long createTime);

    /**
     * <p>根据订单状态删除<p/>
     * @param id
     * @return
     */
    @Delete("delete from `order` where id=#{id}")
    int deleteById(@Param("id") int id);

    /**
     * <p>对订单状态的修改<p/>
     * @param payStatus
     * @return
     */
    @Update("update `order` set `pay_status` = #{payStatus}, `payed_time`=#{payedTime} where order_id=#{orderId}")
    int updateOrder(@Param("orderId")String orderId, @Param("payStatus")int payStatus, @Param("payedTime")long payedTime);

    /**
     * <p>查找全部订单<p/>
     * @return
     */
    @Select("select * from `order` order by id desc")
    List<Order> findAll();

    /**
     * <p>根据订单号查询订单<p/>
     * @param orderId
     * @return
     */
    @Select("select * from `order` where order_id=#{orderId}")
    Order findByOrderId(@Param("orderId") String orderId);

    /**
     * <p>根据会员id查找订单信息</p>
     */
    @Select("select * from `order` where member_id = #{memberId} order by id desc")
    List<Order> findByMemberId(@Param("memberId") int memberId);
}
